define(['apps/utils/tools','apps/utils/math'],function (tools,math){
   /**
   * 根据传过来的行业参数 与企业值  获取分数
   * 优秀值  excellent
   * 良好值  good
   * 平均值  average
   * 较低值  lowers
   * 较差值  bad
   */
  function getIndustryScoreByValue(inds,value){
  	 var result = 0,excellent = inds["excellent"],good = inds["good"],
  	 average = inds["average"],lowers = inds["lowers"],bad = inds["bad"];
  	 if(value >excellent){//大于优秀值给10分
  	      result = 10
  	 }else if(value == excellent){//等于优秀值给9分
  	 	  result = 9;
  	 }else if(excellent < value && value > good){//大于良好值并且小于优秀值给9分
  	 	  result = 8;
  	 }else if(value == good){//等于良好值给7分
  	 	  result = 7;
  	 }else if(good < value && value > average){//大于平均值并且小于良好值给6分
  	 	  result = 6;
  	 }else if(value == average){//等于平均值给5分
  	 	  result = 5;
  	 }else if(average < value && value > lowers){//大于平均值并且小于较低值给4分
  	 	  result = 4;
  	 }else if(value == lowers){//等于较低值给3分
  	 	  result = 3;
  	 }else if(lowers < value && value > bad){//大于较差值并且小于较低值给2分
  	 	  result = 2;
  	 }else if(value == bad){//等于较差值给1分
  	 	  result = 1;
  	 }else if(value < bad){//小于较差值给0分
  	      result = 0;
  	 }
  	 return result;
  }
    function getBootStrapRow(exp,vars,industry){
    	tools.console(industry["sname"]);
    	  var tr = "<tr><th>"+industry["sname"]+"</th>";
    	      tr += "<td>"+industry["excellent"]+"</td>";
    	      tr += "<td>"+industry["good"]+"</td>";
    	      tr += "<td>"+industry["average"]+"</td>";
    	      tr += "<td>"+industry["lowers"]+"</td>";
    	      tr += "<td>"+industry["bad"]+"</td>";
    	    var value = getVarEval(vars);
    	    var score = getIndustryScoreByValue(industry,value);
    	    tr += "<td>"+math.formatNumber(value,2);+"</td>";
    	    tr += "<td>"+score+"</td>";
    	    
    	    tr += "</tr>";
    	    $("#ylnlTable").append(tr);
        return score;
    }
    function createIndustryTable(){
          if(scope.module["id"] == "ylnl"){
          	 var inds = scope.module["industry"];
          	 var exp = "jzcsyv*0.35+zzcbzv*0.25+xsmlrv*0.08+yyxjbzbs*0.08+cbfylrv*0.08+zbsyv*0.08+cbfze*0.08";
             for(var key in inds){
                  var score = getBootStrapRow(exp,key,inds[key]);
                  exp = exp.replaceAll(key,score);
             }
             exp = eval("("+exp+")");
             $("#ylnlTable").append(" <tr><th colspan=7>综合得分</th> <th>"+math.formatNumber(exp,2)+"</th></tr>");
          }	
    }
    /**
     * 初始方法
     */
    function init(module){
    	try{
    	   createIndustryTable();
    	   tools.console("【"+module["title"]+"】对标模型成功初始了init所有可视化组件！>>>>>>>>>>>>>>>>>>>init");
    	}catch(e){
    	   tools.errorInfo("初始【"+module["title"]+"】模型失败！"+e);
    	}
    }
  return {
    createIndustryTable: createIndustryTable,
    getBootStrapRow: getBootStrapRow,
    getIndustryScoreByValue: getIndustryScoreByValue,
    init:init
  }
});